(function(){
  'use strict';

  // create
  var officeAddin = angular.module('officeAddin', [
    'ngRoute',
    'ngSanitize'
  ]);

  officeAddin.config(['$logProvider', function($logProvider){
    if ($logProvider.debugEnabled) {
      $logProvider.debugEnabled(true);
    }
  }]);

   officeAddin.directive('app', [function(){
     return {
       restrict: 'E', 
       template: '<div data-ng-view></div>',
     };
   }]);

  // when Office has initalized, manually bootstrap the app
  // Office.initialize = function(){
  //   console.log('>>> Office.initialize()');
  //   angular.bootstrap(document.getElementById('container'), ['officeAddin']);
  // };

  angular.element(document).ready(function(){
    sleep(1000*3,function(){
      angular.bootstrap(document, ['officeAddin']);
    });    
  }) 

  var sleep = function(millis,callback){
    var now = new Date();
    var exitTime = now.getTime() + millis;
    while(true){
      now = new Date();
      if(now.getTime() > exitTime){
        break;
      }
    }
    if(callback){
      callback();
    }
  }

})();
